<?php

/*
 * Treasure 5$
 * 
 * +1$
 * +1 buy
 * When you play this, you may play a Treasure from your hand twice. If you do, trash that Treasure.
 */

class Counterfeit extends Card implements iKingdom, iDarkAges, iTreasure {

    public function __construct() {
        parent::__construct("Counterfeit", 5);
        $this->value = new Price(1);
        $this->undoPlay = false;
        $this->undoBuy = true;
    }

    public function getDescription() {
        return array(
            "+1$",
            "+1 buy",
            "When you play this, you may play a Treasure from your hand twice. If you do, trash that Treasure.");
    }
    
    public function autoPlayNum(Game $game) {
        return -1;
    }

    public function play(Game $game, $isRealCard) {
        $game->addBuys(1);
        $playHand = $game->getPlayHand();
        $treasures = array();
        foreach ($playHand as $card) {
            if ($card instanceof iTreasure) {
                $treasures[] = $card;
            }
        }

        $treasures = getUniqueCards($treasures);
        if (sizeof($treasures) > 0) {
            $treasures[] = new Option(1, "None");
            $output = MySocket::GetUserReply($game, Input_ChooseOne, $treasures, 1, 1, null, "Choose treasure to play twice");
            $answer = $output[0];
            if ($answer != 'None') {
                ScreenDisplay::addScreenMessage($game, true, "play " . nicePrint($answer) . " twice", "plays " . ScreenDisplay::$LMSG . " twice");
                $card = n2c($answer);
                $trashed_card = $game->moveCardFromPileToPile($card, PlayHand, Trash);
                ScreenDisplay::addScreenMessage($game, false, " and trash " . nicePrint($trashed_card) , " and trashes " . ScreenDisplay::$LMSG);
                $game->pushCardToStack($card, VIRTUAL_CARD);
                $game->pushCardToStack($card, VIRTUAL_CARD);
            } else {
                ScreenDisplay::addScreenMessage($game, true, "play nothing twice", "plays nothing twice");
            }
        } else {
            ScreenDisplay::addScreenMessage($game, true, "play nothing twice", "plays nothing twice");
        }
        $game->cardPaymentFinished();
        return true;
    }

}

?>